package com.springboot.caiji.service.impl;

import com.springboot.caiji.entity.TRestinfo;
import com.springboot.caiji.entity.view.TrestInfoView;
import com.springboot.caiji.mapper.TRestinfoMapper;
import com.springboot.caiji.service.ITMydata00Service;
import com.springboot.caiji.service.ITMydata01Service;
import com.springboot.caiji.service.ITRestinfoService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author author
 * @since 2024-06-27
 */
@Service
public class TRestinfoServiceImpl extends ServiceImpl<TRestinfoMapper, TRestinfo> implements ITRestinfoService {

    @Autowired
    private ITMydata00Service itMydata00Service;

    @Autowired
    private ITMydata01Service itMydata01Service;

    @Override
    public List<TrestInfoView> getAll() {
        List<TrestInfoView> infoViewList=new ArrayList<>();
        List<TRestinfo> restinfoList=this.list();
        TrestInfoView trestInfoView=null;
        for (TRestinfo tRestinfo : restinfoList) {
            //去数据1查询
            try{
                trestInfoView=itMydata01Service.getByName(tRestinfo.getPointName());
                if(trestInfoView!=null){
                    infoViewList.add(trestInfoView);
                    continue;
                }else{
                    //去数据库二查询
                    trestInfoView=itMydata00Service.getByName(tRestinfo.getPointName());
                    if(trestInfoView!=null){
                        infoViewList.add(trestInfoView);
                    }
                }
            }catch (Exception ex){
                //去数据库二查询
                trestInfoView=itMydata00Service.getByName(tRestinfo.getPointName());
                if(trestInfoView!=null){
                    infoViewList.add(trestInfoView);
                }
            }


        }
        return infoViewList;
    }


}
